using System;
using System.Collections.Generic;
using EnvDTE;
using NDomain.Helpers;
using NDomain.Reflection;
namespace NDomain.DomainExplorer
{
    internal class DTE2ClassInfoProvider : IClassInfoProvider
    {
        private CodeNamespace _codeNamespace;

        public CodeClass codeClass
        {
            get { return _codeClass; }
        }

        private CodeClass _codeClass;
        private List<DTE2AttributeInfoProvider> _attributes;
        private List<string> _interfaces;

        public DTE2ClassInfoProvider(CodeNamespace codeNamespace, CodeClass codeClass)
        {
            _codeNamespace = codeNamespace;
            _codeClass = codeClass;
        }

        public IList<IAttributeInfoProvider> GetAttributes()
        {
            if (_attributes == null)
            {
                _attributes = new List<DTE2AttributeInfoProvider>();
                foreach (CodeAttribute codeAttribute in IEnumerableHelper.Filter<CodeAttribute>(_codeClass.Children))
                    _attributes.Add(new DTE2AttributeInfoProvider(codeAttribute));
            }
            return _attributes.ToArray();
        }

        public string GetName()
        {
            return _codeClass.Name;
        }

        public string GetNamespace()
        {
            return _codeNamespace.FullName;
        }

        public string[] GetImplementedInterfaces()
        {
            if (_interfaces == null)
            {
                _interfaces = new List<string>();
                foreach (CodeInterface codeInterface in _codeClass.ImplementedInterfaces)
                    _interfaces.Add(codeInterface.FullName);
            }

            return _interfaces.ToArray();
        }
    }
}